home *** CD-ROM | disk | FTP | other *** search
/ Go64! / Go64_2002-02_2002_CSW_Side_A.d64 / 3d matrixrot.txt < prev    next >
Text File  |  2023-02-26  |  29KB  |  1,369 lines

  1.         ; go64! tutorial on 3-d graphics
  2.         ; part 3: matrix rotation
  3.  
  4.         ; go64! 3d-kurs
  5.         ; teil 3: matrixrotation
  6.  
  7.  
  8. vicbank  = %00000011; $0000-$4000
  9. v        = vicbank($03*$4000;=$0000
  10. screen   = $0400
  11. charset  = $0800
  12.  
  13. xaddlotb = $2000
  14. xaddhitb = $2080
  15. pixeltab = $2100
  16.  
  17.  
  18. basezp   = $02
  19. pointers = $00+basezp
  20. alphalo  = $02+basezp
  21. betalo   = $03+basezp
  22. gammalo  = $04+basezp
  23. alpha    = $05+basezp
  24. beta     = $06+basezp
  25. gamma    = $07+basezp
  26. sinbufl0 = $08+basezp
  27. sinbufh0 = $09+basezp
  28. sinbufl1 = $0a+basezp
  29. sinbufh1 = $0b+basezp
  30. unitxxlo = $0c+basezp
  31. unitxxhi = $0d+basezp
  32. unitxylo = $0e+basezp
  33. unitxyhi = $0f+basezp
  34. unitxzlo = $10+basezp
  35. unitxzhi = $11+basezp
  36. unityxlo = $12+basezp
  37. unityxhi = $13+basezp
  38. unityylo = $14+basezp
  39. unityyhi = $15+basezp
  40. unityzlo = $16+basezp
  41. unityzhi = $17+basezp
  42. unitzxlo = $18+basezp
  43. unitzxhi = $19+basezp
  44. unitzylo = $1a+basezp
  45. unitzyhi = $1b+basezp
  46. unitzzlo = $1c+basezp
  47. unitzzhi = $1d+basezp
  48. dividend = $1e+basezp
  49. divisor  = $20+basezp
  50. x2dcrdfr = $23+basezp
  51. z2dcrdfr = $2b+basezp
  52. x2dcords = $33+basezp
  53. y2dcords = $3b+basezp
  54. z2dcords = $43+basezp
  55. oldxcrds = $4b+basezp
  56. oldycrds = $53+basezp
  57.  
  58. foregndc = $01
  59. backgndc = $06
  60.  
  61. xpos     = $0c; char matrix coordinates
  62. ypos     = $05; zeichenmatrixkoordinaten
  63.  
  64. alphaadd = $ffff+1-($0200/3)
  65. betaadd  = $0700/3; angle add values
  66. gammaadd = $0300/3; winkeladditionswerte
  67.  
  68. numpoint = $08
  69.  
  70.  
  71.          *= $4000
  72.  
  73.          sei
  74.          lda #$35
  75.          sta $01
  76.          lda #<return;nmi
  77.          sta $fffa
  78.          lda #>return;nmi
  79.          sta $fffb
  80.          bit $d011
  81.          bpl *-3
  82.          bit $d011
  83.          bmi *-3
  84.          lda #$00
  85.          sta $d011
  86.          lda #backgndc
  87.          sta $d020
  88.          sta $d021
  89.  
  90.  
  91.          ; build tables
  92.          ; tabellen generieren
  93.  
  94.          lda #<charset+v
  95.          ldx #>charset+v
  96.          ldy #$00
  97.          .byte $24
  98. mkxaddtb pla
  99.          sta xaddlotb,y
  100.          pha
  101.          txa
  102.          sta xaddhitb,y
  103.          iny
  104.          tya
  105.          and #%00000111
  106.          bne mkxaddtb+0
  107.          pla
  108.          clc
  109.          adc #$80
  110.          bcc *+3
  111.          inx
  112.          cpy #$80
  113.          bne mkxaddtb+1
  114.  
  115.          lda #%10000000
  116.          ldx #$00
  117. makpxltb sta pixeltab,x
  118.          tay
  119.          lsr a
  120.          tya
  121.          ror a
  122.          inx
  123.          bpl makpxltb
  124.  
  125.          ldx #$00
  126.          lda sincoslo+$00,x
  127.          sta sincoslo+$0100,x
  128.          lda sincoshi+$00,x
  129.          sta sincoshi+$0100,x
  130.          inx
  131.          bne *-13
  132.  
  133.          ; clear charset
  134.          ; zeichensatz loeschen
  135.  
  136.          lda #<charset+v
  137.          sta pointers+0
  138.          lda #>charset+v
  139.          sta pointers+1
  140.          lda #$00
  141.          ldx #$08
  142.          tay
  143. clearchr sta (pointers+0),y
  144.          iny
  145.          bne clearchr
  146.          inc pointers+1
  147.          dex
  148.          bne clearchr
  149.  
  150.  
  151.          ; clear screen
  152.          ; bildschirm loeschen
  153.  
  154.          lda #$00
  155.          tax
  156.          sta screen+v+$00,x
  157.          sta screen+v+$0100,x
  158.          sta screen+v+$0200,x
  159.          sta screen+v+$0300,x
  160.          inx
  161.          bne *-13
  162.  
  163.  
  164.          ; set up screen matrix
  165.          ; bildschirmmatrix bilden
  166.  
  167.          clc
  168.          lda #<xpos+(ypos*$28)+screen+v
  169.          sta pointers+0
  170.          lda #>xpos+(ypos*$28)+screen+v
  171.          sta pointers+1
  172.          ldx #$00
  173. setupscr txa
  174.          ldy #$00
  175.          sta (pointers+0),y
  176.          adc #$10
  177.          iny
  178.          cpy #$10
  179.          bne setupscr+3
  180.          lda #$27
  181.          adc pointers+0
  182.          sta pointers+0
  183.          bcc *+4
  184.          inc pointers+1
  185.          inx
  186.          cpx #$10
  187.          bne setupscr
  188.  
  189.  
  190.          ; set foreground colour
  191.          ; vordergrundfarbe setzen
  192.  
  193.          lda #foregndc
  194.          ldx #$00
  195.          sta $d800,x
  196.          sta $d900,x
  197.          sta $da00,x
  198.          sta $db00,x
  199.          inx
  200.          bne *-13
  201.  
  202.  
  203.          ; set vic registers
  204.          ; vic-register setzen
  205.  
  206.          bit $d011
  207.          bpl *-3
  208.          bit $d011
  209.          bmi *-3
  210.          lda #%00011011
  211.          sta $d011
  212.          lda #%00001000
  213.          sta $d016
  214.          lda #screen/$40.(charset/$0400)
  215.          sta $d018
  216.          lda $dd00
  217.          and #%00000011
  218.          ora #vicbank
  219.          sta $dd00
  220.  
  221.  
  222.          ; reset angles and coordinates
  223.          ; koordinaten&winkel nullsetzen
  224.  
  225.          lda #$00
  226.          ldx #numpoint-1
  227.          sta oldxcrds,x
  228.          sta oldycrds,x
  229.          dex
  230.          bpl *-5
  231.          sta alphalo
  232.          sta betalo
  233.          sta gammalo
  234.          sta alpha
  235.          sta beta
  236.          sta gamma
  237.  
  238.  
  239.          ; main loop
  240.          ; hauptschleife
  241.  
  242. mainloop ; rotate unit vectors
  243.          ; (absolutely unoptimized)
  244.          ; einheitsvektoren rotieren
  245.          ; (absolut unoptimiert)
  246.  
  247.           ;   cos (beta) * cos (gamma)
  248.          clc
  249.          lda beta
  250.          adc #$40          ; (cos)
  251.          sec
  252.          sbc gamma
  253.          sec
  254.          sbc #$40          ; (cos)
  255.          tax               ; beta-gamma
  256.          clc
  257.          lda beta
  258.          adc #$40          ; (cos)
  259.          clc
  260.          adc gamma
  261.          clc
  262.          adc #$40          ; (cos)
  263.          tay               ; beta+gamma
  264.          sec
  265.          lda sincoslo+$40,x
  266.          sbc sincoslo+$40,y
  267.          sta unitxxlo
  268.          lda sincoshi+$40,x;    cos(b-g)
  269.          sbc sincoshi+$40,y;  - cos(b+g)
  270.          sta unitxxhi
  271.  
  272.           ; - sin(a) * sin(b) * cos(g)
  273.           ; - cos(a) * sin(g)
  274.          clc
  275.          lda beta
  276.          adc gamma
  277.          clc
  278.          adc #$40     ; (cos)
  279.          sec
  280.          sbc alpha
  281.          sec
  282.          sbc #$80     ; (-)
  283.          tax          ; beta+gamma-alpha
  284.          clc
  285.          lda alpha
  286.          adc #$80     ; (-)
  287.          clc
  288.          adc gamma
  289.          clc
  290.          adc #$40     ; (cos)
  291.          sec
  292.          sbc beta
  293.          tay          ; alpha+gamma-beta
  294.          clc
  295.          lda sincoslo+$00,x
  296.          adc sincoslo+$00,y
  297.          sta sinbufl0
  298.          lda sincoshi+$00,x;  sin(b+g-a)
  299.          adc sincoshi+$00,y;+ sin(a+g-b)
  300.          sta sinbufh0
  301.          clc
  302.          lda alpha
  303.          adc #$80     ; (-)
  304.          clc
  305.          adc beta
  306.          sec
  307.          sbc gamma
  308.          sec
  309.          sbc #$40     ; (cos)
  310.          tax          ; alpha+beta-gamma
  311.          clc
  312.          lda alpha
  313.          adc #$80     ; (-)
  314.          clc
  315.          adc beta
  316.          clc
  317.          adc gamma
  318.          clc
  319.          adc #$40     ; (cos)
  320.          tay          ; alpha+beta+gamma
  321.          sec
  322.          lda sincoslo+$00,x
  323.          sbc sincoslo+$00,y
  324.          sta sinbufl1
  325.          lda sincoshi+$00,x;  sin(a+b-g)
  326.          sbc sincoshi+$00,y;- sin(a+b+g)
  327.          sta sinbufh1
  328.          clc
  329.          lda sinbufl0
  330.          adc sinbufl1
  331.          sta sinbufl1
  332.          lda sinbufh0
  333.          adc sinbufh1
  334.          cmp #$80
  335.          ror a  ; - sin(a)*sin(b)*cos(g)
  336.          ror sinbufl1
  337.          sta sinbufh1
  338.  
  339.          clc
  340.          lda alpha
  341.          adc #$40+$80      ; (-cos)
  342.          sec
  343.          sbc gamma
  344.          tax               ; alpha-gamma
  345.          clc
  346.          lda alpha
  347.          adc #$40+$80      ; (-cos)
  348.          clc
  349.          adc gamma
  350.          tay               ; alpha+gamma
  351.          sec
  352.          lda sincoslo+$40,x
  353.          sbc sincoslo+$40,y
  354.          sta sinbufl0      ;    cos(a-g)
  355.          lda sincoshi+$40,x;  - cos(a+g)
  356.          sbc sincoshi+$40,y
  357.          sta sinbufh0  ; - cos(a)*sin(g)
  358.  
  359.          clc
  360.          lda sinbufl0
  361.          adc sinbufl1
  362.          sta unitxylo
  363.          lda sinbufh0
  364.          adc sinbufh1
  365.          sta unitxyhi
  366.  
  367.           ;   cos(a) * sin(b) * cos(g)
  368.           ; - sin(a) * sin(g)
  369.          clc
  370.          lda beta
  371.          adc gamma
  372.          clc
  373.          adc #$40     ; (cos)
  374.          sec
  375.          sbc alpha
  376.          sec
  377.          sbc #$40     ; (cos)
  378.          tax          ; beta+gamma-alpha
  379.          clc
  380.          lda alpha
  381.          adc #$40     ; (cos)
  382.          clc
  383.          adc gamma
  384.          clc
  385.          adc #$40     ; (cos)
  386.          sec
  387.          sbc beta
  388.          tay          ; alpha+gamma-beta
  389.          clc
  390.          lda sincoslo+$00,x
  391.          adc sincoslo+$00,y
  392.          sta sinbufl0
  393.          lda sincoshi+$00,x;  sin(b+g-a)
  394.          adc sincoshi+$00,y;+ sin(a+g-b)
  395.          sta sinbufh0
  396.          clc
  397.          lda alpha
  398.          adc #$40     ; (cos)
  399.          clc
  400.          adc beta
  401.          sec
  402.          sbc gamma
  403.          sec
  404.          sbc #$40     ; (cos)
  405.          tax          ; alpha+beta-gamma
  406.          clc
  407.          lda alpha
  408.          adc #$40     ; (cos)
  409.          clc
  410.          adc beta
  411.          clc
  412.          adc gamma
  413.          clc
  414.          adc #$40     ; (cos)
  415.          tay          ; alpha+beta+gamma
  416.          sec
  417.          lda sincoslo+$00,x
  418.          sbc sincoslo+$00,y
  419.          sta sinbufl1
  420.          lda sincoshi+$00,x;  sin(a+b-g)
  421.          sbc sincoshi+$00,y;- sin(a+b+g)
  422.          sta sinbufh1
  423.          clc
  424.          lda sinbufl0
  425.          adc sinbufl1
  426.          sta sinbufl1
  427.          lda sinbufh0
  428.          adc sinbufh1
  429.          cmp #$80
  430.          ror a    ; cos(a)*sin(b)*cos(g)
  431.          ror sinbufl1
  432.          sta sinbufh1
  433.  
  434.          clc
  435.          lda alpha
  436.          adc #$80          ; (-)
  437.          sec
  438.          sbc gamma
  439.          tax               ; alpha-gamma
  440.          clc
  441.          lda alpha
  442.          adc #$80          ; (-)
  443.          clc
  444.          adc gamma
  445.          tay               ; alpha+gamma
  446.          sec
  447.          lda sincoslo+$40,x
  448.          sbc sincoslo+$40,y
  449.          sta sinbufl0      ;    cos(a-g)
  450.          lda sincoshi+$40,x;  - cos(a+g)
  451.          sbc sincoshi+$40,y
  452.          sta sinbufh0  ; - sin(a)*sin(g)
  453.  
  454.          clc
  455.          lda sinbufl0
  456.          adc sinbufl1
  457.          sta unitxzlo
  458.          lda sinbufh0
  459.          adc sinbufh1
  460.          sta unitxzhi
  461.  
  462.  
  463.           ; - cos (beta) * sin (gamma)
  464.          clc
  465.          lda beta
  466.          adc #$40+$80      ; (-cos)
  467.          sec
  468.          sbc gamma
  469.          tax               ; beta-gamma
  470.          clc
  471.          lda beta
  472.          adc #$40+$80      ; (-cos)
  473.          clc
  474.          adc gamma
  475.          tay               ; beta+gamma
  476.          sec
  477.          lda sincoslo+$40,x
  478.          sbc sincoslo+$40,y
  479.          sta unityxlo
  480.          lda sincoshi+$40,x;    cos(b-g)
  481.          sbc sincoshi+$40,y;  - cos(b+g)
  482.          sta unityxhi
  483.  
  484.           ;   sin(a) * sin(b) * sin(g)
  485.           ; - cos(a) * cos(g)
  486.          clc
  487.          lda beta
  488.          adc gamma
  489.          sec
  490.          sbc alpha
  491.          tax          ; beta+gamma-alpha
  492.          clc
  493.          lda alpha
  494.          adc gamma
  495.          sec
  496.          sbc beta
  497.          tay          ; alpha+gamma-beta
  498.          clc
  499.          lda sincoslo+$00,x
  500.          adc sincoslo+$00,y
  501.          sta sinbufl0
  502.          lda sincoshi+$00,x;  sin(b+g-a)
  503.          adc sincoshi+$00,y;+ sin(a+g-b)
  504.          sta sinbufh0
  505.          clc
  506.          lda alpha
  507.          adc beta
  508.          sec
  509.          sbc gamma
  510.          tax          ; alpha+beta-gamma
  511.          clc
  512.          lda alpha
  513.          adc beta
  514.          clc
  515.          adc gamma
  516.          tay          ; alpha+beta+gamma
  517.          sec
  518.          lda sincoslo+$00,x
  519.          sbc sincoslo+$00,y
  520.          sta sinbufl1
  521.          lda sincoshi+$00,x;  sin(a+b-g)
  522.          sbc sincoshi+$00,y;- sin(a+b+g)
  523.          sta sinbufh1
  524.          clc
  525.          lda sinbufl0
  526.          adc sinbufl1
  527.          sta sinbufl1
  528.          lda sinbufh0
  529.          adc sinbufh1
  530.          cmp #$80
  531.          ror a    ; sin(a)*sin(b)*sin(g)
  532.          ror sinbufl1
  533.          sta sinbufh1
  534.  
  535.          clc
  536.          lda alpha
  537.          adc #$40+$80      ; (-cos)
  538.          sec
  539.          sbc gamma
  540.          sec
  541.          sbc #$40          ; (cos)
  542.          tax               ; alpha-gamma
  543.          clc
  544.          lda alpha
  545.          adc #$40+$80      ; (-cos)
  546.          clc
  547.          adc gamma
  548.          clc
  549.          adc #$40          ; (cos)
  550.          tay               ; alpha+gamma
  551.          sec
  552.          lda sincoslo+$40,x
  553.          sbc sincoslo+$40,y
  554.          sta sinbufl0      ;    cos(a-g)
  555.          lda sincoshi+$40,x;  - cos(a+g)
  556.          sbc sincoshi+$40,y
  557.          sta sinbufh0  ; - cos(a)*cos(g)
  558.  
  559.          clc
  560.          lda sinbufl0
  561.          adc sinbufl1
  562.          sta unityylo
  563.          lda sinbufh0
  564.          adc sinbufh1
  565.          sta unityyhi
  566.  
  567.           ; - cos(a) * sin(b) * sin(g)
  568.           ; - sin(a) * cos(g)
  569.          clc
  570.          lda beta
  571.          adc gamma
  572.          sec
  573.          sbc alpha
  574.          sec
  575.          sbc #$40+$80 ; (-cos)
  576.          tax          ; beta+gamma-alpha
  577.          clc
  578.          lda alpha
  579.          adc #$40+$80 ; (-cos)
  580.          clc
  581.          adc gamma
  582.          sec
  583.          sbc beta
  584.          tay          ; alpha+gamma-beta
  585.          clc
  586.          lda sincoslo+$00,x
  587.          adc sincoslo+$00,y
  588.          sta sinbufl0
  589.          lda sincoshi+$00,x;  sin(b+g-a)
  590.          adc sincoshi+$00,y;+ sin(a+g-b)
  591.          sta sinbufh0
  592.          clc
  593.          lda alpha
  594.          adc #$40+$80 ; (-cos)
  595.          adc beta
  596.          sec
  597.          sbc gamma
  598.          tax          ; alpha+beta-gamma
  599.          clc
  600.          lda alpha
  601.          adc #$40+$80 ; (-cos)
  602.          clc
  603.          adc beta
  604.          clc
  605.          adc gamma
  606.          tay          ; alpha+beta+gamma
  607.          sec
  608.          lda sincoslo+$00,x
  609.          sbc sincoslo+$00,y
  610.          sta sinbufl1
  611.          lda sincoshi+$00,x;  sin(a+b-g)
  612.          sbc sincoshi+$00,y;- sin(a+b+g)
  613.          sta sinbufh1
  614.          clc
  615.          lda sinbufl0
  616.          adc sinbufl1
  617.          sta sinbufl1
  618.          lda sinbufh0
  619.          adc sinbufh1
  620.          cmp #$80
  621.          ror a  ; - cos(a)*sin(b)*sin(g)
  622.          ror sinbufl1
  623.          sta sinbufh1
  624.  
  625.          clc
  626.          lda alpha
  627.          adc #$80          ; (-)
  628.          sec
  629.          sbc gamma
  630.          sec
  631.          sbc #$40          ; (cos)
  632.          tax               ; alpha-gamma
  633.          clc
  634.          lda alpha
  635.          adc #$80          ; (-)
  636.          clc
  637.          adc gamma
  638.          clc
  639.          adc #$40          ; (cos)
  640.          tay               ; alpha+gamma
  641.          sec
  642.          lda sincoslo+$40,x
  643.          sbc sincoslo+$40,y
  644.          sta sinbufl0      ;    cos(a-g)
  645.          lda sincoshi+$40,x;  - cos(a+g)
  646.          sbc sincoshi+$40,y
  647.          sta sinbufh0  ; - sin(a)*cos(g)
  648.  
  649.          clc
  650.          lda sinbufl0
  651.          adc sinbufl1
  652.          sta unityzlo
  653.          lda sinbufh0
  654.          adc sinbufh1
  655.          sta unityzhi
  656.  
  657.  
  658.           ;   sin (beta)
  659.          ldx beta
  660.          lda sincoslo+$00,x
  661.          asl a
  662.          sta unitzxlo
  663.          lda sincoshi+$00,x
  664.          rol a
  665.          sta unitzxhi
  666.  
  667.           ;   sin (alpha) * cos (beta)
  668.          sec
  669.          lda alpha
  670.          sbc beta
  671.          sec
  672.          sbc #$40          ; (cos)
  673.          tax               ; alpha-beta
  674.          clc
  675.          lda alpha
  676.          adc beta
  677.          clc
  678.          adc #$40          ; (cos)
  679.          tay               ; alpha+beta
  680.          sec
  681.          lda sincoslo+$40,x
  682.          sbc sincoslo+$40,y
  683.          sta unitzylo
  684.          lda sincoshi+$40,x;    cos(a-b)
  685.          sbc sincoshi+$40,y;  - cos(a+b)
  686.          sta unitzyhi
  687.  
  688.           ; - cos (alpha) * cos (beta)
  689.          clc
  690.          lda alpha
  691.          adc #$80+$40      ; (-cos)
  692.          sec
  693.          sbc beta
  694.          sec
  695.          sbc #$40          ; (cos)
  696.          tax               ; alpha-beta
  697.          clc
  698.          lda alpha
  699.          adc #$80+$40      ; (-cos)
  700.          clc
  701.          adc beta
  702.          clc
  703.          adc #$40          ; (cos)
  704.          tay               ; alpha+beta
  705.          clc
  706.          lda sincoslo+$40,x
  707.          sbc sincoslo+$40,y
  708.          sta unitzzlo
  709.          lda sincoshi+$40,x;    cos(a-b)
  710.          sbc sincoshi+$40,y;  - cos(a+b)
  711.          sta unitzzhi
  712.  
  713.  
  714.  
  715.          ; calculate new coordinates
  716.          ; pretty unoptimized too
  717.          ; neue koordinaten berechnen
  718.          ; auch ziemlich unoptimiert
  719.  
  720.           ; p(-1;+1;+1)
  721.          sec
  722.          lda unitxylo
  723.          sbc unitxxlo
  724.          tax
  725.          lda unitxyhi
  726.          sbc unitxxhi
  727.          tay
  728.          clc
  729.          txa
  730.          adc unitxzlo
  731.          sta x2dcrdfr+$00
  732.          tya
  733.          adc unitxzhi
  734.          sta x2dcords+$00
  735.  
  736.          sec
  737.          lda unityylo
  738.          sbc unityxlo
  739.          tax
  740.          lda unityyhi
  741.          sbc unityxhi
  742.          tay
  743.          clc
  744.          txa
  745.          adc unityzlo
  746.          tya
  747.          adc unityzhi
  748.          sta y2dcords+$00
  749.  
  750.          sec
  751.          lda unitzylo
  752.          sbc unitzxlo
  753.          tax
  754.          lda unitzyhi
  755.          sbc unitzxhi
  756.          tay
  757.          clc
  758.          txa
  759.          adc unitzzlo
  760.          sta z2dcrdfr+$00
  761.          tya
  762.          adc unitzzhi
  763.          sta z2dcords+$00
  764.  
  765.           ; p(+1;+1;+1)
  766.          clc
  767.          lda unitxxlo
  768.          adc unitxylo
  769.          tax
  770.          lda unitxxhi
  771.          adc unitxyhi
  772.          tay
  773.          clc
  774.          txa
  775.          adc unitxzlo
  776.          sta x2dcrdfr+$01
  777.          tya
  778.          adc unitxzhi
  779.          sta x2dcords+$01
  780.  
  781.          clc
  782.          lda unityxlo
  783.          adc unityylo
  784.          tax
  785.          lda unityxhi
  786.          adc unityyhi
  787.          tay
  788.          clc
  789.          txa
  790.          adc unityzlo
  791.          tya
  792.          adc unityzhi
  793.          sta y2dcords+$01
  794.  
  795.          clc
  796.          lda unitzxlo
  797.          adc unitzylo
  798.          tax
  799.          lda unitzxhi
  800.          adc unitzyhi
  801.          tay
  802.          clc
  803.          txa
  804.          adc unitzzlo
  805.          sta z2dcrdfr+$01
  806.          tya
  807.          adc unitzzhi
  808.          sta z2dcords+$01
  809.  
  810.           ; p(-1;+1;-1)
  811.          sec
  812.          lda unitxylo
  813.          sbc unitxxlo
  814.          tax
  815.          lda unitxyhi
  816.          sbc unitxxhi
  817.          tay
  818.          sec
  819.          txa
  820.          sbc unitxzlo
  821.          sta x2dcrdfr+$02
  822.          tya
  823.          sbc unitxzhi
  824.          sta x2dcords+$02
  825.  
  826.          sec
  827.          lda unityylo
  828.          sbc unityxlo
  829.          tax
  830.          lda unityyhi
  831.          sbc unityxhi
  832.          tay
  833.          sec
  834.          txa
  835.          sbc unityzlo
  836.          tya
  837.          sbc unityzhi
  838.          sta y2dcords+$02
  839.  
  840.          sec
  841.          lda unitzylo
  842.          sbc unitzxlo
  843.          tax
  844.          lda unitzyhi
  845.          sbc unitzxhi
  846.          tay
  847.          sec
  848.          txa
  849.          sbc unitzzlo
  850.          sta z2dcrdfr+$02
  851.          tya
  852.          sbc unitzzhi
  853.          sta z2dcords+$02
  854.  
  855.           ; p(+1;+1;-1)
  856.          clc
  857.          lda unitxxlo
  858.          adc unitxylo
  859.          tax
  860.          lda unitxxhi
  861.          adc unitxyhi
  862.          tay
  863.          sec
  864.          txa
  865.          sbc unitxzlo
  866.          sta x2dcrdfr+$03
  867.          tya
  868.          sbc unitxzhi
  869.          sta x2dcords+$03
  870.  
  871.          clc
  872.          lda unityxlo
  873.          adc unityylo
  874.          tax
  875.          lda unityxhi
  876.          adc unityyhi
  877.          tay
  878.          sec
  879.          txa
  880.          sbc unityzlo
  881.          tya
  882.          sbc unityzhi
  883.          sta y2dcords+$03
  884.  
  885.          clc
  886.          lda unitzxlo
  887.          adc unitzylo
  888.          tax
  889.          lda unitzxhi
  890.          adc unitzyhi
  891.          tay
  892.          sec
  893.          txa
  894.          sbc unitzzlo
  895.          sta z2dcrdfr+$03
  896.          tya
  897.          sbc unitzzhi
  898.          sta z2dcords+$03
  899.  
  900.           ; p(-1;-1;+1)
  901.          sec
  902.          lda unitxzlo
  903.          sbc unitxxlo
  904.          tax
  905.          lda unitxzhi
  906.          sbc unitxxhi
  907.          tay
  908.          sec
  909.          txa
  910.          sbc unitxylo
  911.          sta x2dcrdfr+$04
  912.          tya
  913.          sbc unitxyhi
  914.          sta x2dcords+$04
  915.  
  916.          sec
  917.          lda unityzlo
  918.          sbc unityxlo
  919.          tax
  920.          lda unityzhi
  921.          sbc unityxhi
  922.          tay
  923.          sec
  924.          txa
  925.          sbc unityylo
  926.          tya
  927.          sbc unityyhi
  928.          sta y2dcords+$04
  929.  
  930.          sec
  931.          lda unitzzlo
  932.          sbc unitzxlo
  933.          tax
  934.          lda unitzzhi
  935.          sbc unitzxhi
  936.          tay
  937.          sec
  938.          txa
  939.          sbc unitzylo
  940.          sta z2dcrdfr+$04
  941.          tya
  942.          sbc unitzyhi
  943.          sta z2dcords+$04
  944.  
  945.           ; p(+1;-1;+1)
  946.          sec
  947.          lda unitxxlo
  948.          sbc unitxylo
  949.          tax
  950.          lda unitxxhi
  951.          sbc unitxyhi
  952.          tay
  953.          clc
  954.          txa
  955.          adc unitxzlo
  956.          sta x2dcrdfr+$05
  957.          tya
  958.          adc unitxzhi
  959.          sta x2dcords+$05
  960.  
  961.          sec
  962.          lda unityxlo
  963.          sbc unityylo
  964.          tax
  965.          lda unityxhi
  966.          sbc unityyhi
  967.          tay
  968.          clc
  969.          txa
  970.          adc unityzlo
  971.          tya
  972.          adc unityzhi
  973.          sta y2dcords+$05
  974.  
  975.          sec
  976.          lda unitxzlo
  977.          sbc unitzylo
  978.          tax
  979.          lda unitzxhi
  980.          sbc unitzyhi
  981.          tay
  982.          clc
  983.          txa
  984.          adc unitzzlo
  985.          sta z2dcrdfr+$05
  986.          tya
  987.          adc unitzzhi
  988.          sta z2dcords+$05
  989.  
  990.           ; p(-1;-1;-1)
  991.          sec
  992.          lda #$00
  993.          sbc unitxxlo
  994.          tax
  995.          lda #$00
  996.          sbc unitxxhi
  997.          tay
  998.          sec
  999.          txa
  1000.          sbc unitxylo
  1001.          tax
  1002.          tya
  1003.          sbc unitxyhi
  1004.          tay
  1005.          sec
  1006.          txa
  1007.          sbc unitxzlo
  1008.          sta x2dcrdfr+$06
  1009.          tya
  1010.          sbc unitxzhi
  1011.          sta x2dcords+$06
  1012.  
  1013.          sec
  1014.          lda #$00
  1015.          sbc unityxlo
  1016.          tax
  1017.          lda #$00
  1018.          sbc unityxhi
  1019.          tay
  1020.          sec
  1021.          txa
  1022.          sbc unityylo
  1023.          tax
  1024.          tya
  1025.          sbc unityyhi
  1026.          tay
  1027.          sec
  1028.          txa
  1029.          sbc unityzlo
  1030.          tya
  1031.          sbc unityzhi
  1032.          sta y2dcords+$06
  1033.  
  1034.          sec
  1035.          lda #$00
  1036.          sbc unitzxlo
  1037.          tax
  1038.          lda #$00
  1039.          sbc unitzxhi
  1040.          tay
  1041.          sec
  1042.          txa
  1043.          sbc unitzylo
  1044.          tax
  1045.          tya
  1046.          sbc unitzyhi
  1047.          tay
  1048.          sec
  1049.          txa
  1050.          sbc unitzzlo
  1051.          sta z2dcrdfr+$06
  1052.          tya
  1053.          sbc unitzzhi
  1054.          sta z2dcords+$06
  1055.  
  1056.           ; p(+1;-1;-1)
  1057.          sec
  1058.          lda unitxxlo
  1059.          sbc unitxylo
  1060.          tax
  1061.          lda unitxxhi
  1062.          sbc unitxyhi
  1063.          tay
  1064.          sec
  1065.          txa
  1066.          sbc unitxzlo
  1067.          sta x2dcrdfr+$07
  1068.          tya
  1069.          sbc unitxzhi
  1070.          sta x2dcords+$07
  1071.  
  1072.          sec
  1073.          lda unityxlo
  1074.          sbc unityylo
  1075.          tax
  1076.          lda unityxhi
  1077.          sbc unityyhi
  1078.          tay
  1079.          sec
  1080.          txa
  1081.          sbc unityzlo
  1082.          tya
  1083.          sbc unityzhi
  1084.          sta y2dcords+$07
  1085.  
  1086.          sec
  1087.          lda unitzxlo
  1088.          sbc unitzylo
  1089.          tax
  1090.          lda unitzxhi
  1091.          sbc unitzyhi
  1092.          tay
  1093.          sec
  1094.          txa
  1095.          sbc unitzzlo
  1096.          sta z2dcrdfr+$07
  1097.          tya
  1098.          sbc unitzzhi
  1099.          sta z2dcords+$07
  1100.  
  1101.  
  1102.          ; convert coordinates to 2-d
  1103.          ; koordinaten nach 2d wandeln
  1104.  
  1105.          ldx #numpoint-1
  1106. convto2d ldy x2dcrdfr,x
  1107.          lda x2dcords,x
  1108.          jsr perspect
  1109.          sta x2dcords,x
  1110.          ldy z2dcrdfr,x
  1111.          lda z2dcords,x
  1112.          jsr perspect
  1113.          sta y2dcords,x
  1114.          dex
  1115.          bpl convto2d
  1116.  
  1117.  
  1118.          ; clear the old points
  1119.          ; die alten punkte loeschen
  1120.  
  1121.          bit $d011
  1122.          bpl *-3
  1123.          bit $d011
  1124.          bmi *-3
  1125.  
  1126.          lda #numpoint-1
  1127. clrpoint pha
  1128.          tax
  1129.          lda oldxcrds,x
  1130.          ldy oldycrds,x
  1131.          tax
  1132.          lda xaddlotb,x
  1133.          sta pointers+0
  1134.          lda xaddhitb,x
  1135.          sta pointers+1
  1136.          lda #$ff
  1137.          eor pixeltab,x
  1138.          and (pointers+0),y
  1139.          sta (pointers+0),y
  1140.          pla
  1141.          sec
  1142.          sbc #$01
  1143.          bpl clrpoint
  1144.  
  1145.  
  1146.          ; put the rotated points
  1147.          ; die rotierten punkte setzen
  1148.  
  1149.          lda #numpoint-1
  1150. putpoint pha
  1151.          tax
  1152.          lda x2dcords,x
  1153.          sta oldxcrds,x
  1154.          ldy y2dcords,x
  1155.          sty oldycrds,x
  1156.          tax
  1157.          lda xaddlotb,x
  1158.          sta pointers+0
  1159.          lda xaddhitb,x
  1160.          sta pointers+1
  1161.          lda pixeltab,x
  1162.          ora (pointers+0),y
  1163.          sta (pointers+0),y
  1164.          pla
  1165.          sec
  1166.          sbc #$01
  1167.          bpl putpoint
  1168.  
  1169.  
  1170.          ; advance angles
  1171.          ; winkel erhoehen
  1172.  
  1173.          clc
  1174.          lda #<alphaadd
  1175.          adc alphalo
  1176.          sta alphalo
  1177.          lda #>alphaadd
  1178.          adc alpha
  1179.          sta alpha
  1180.          clc
  1181.          lda #<betaadd
  1182.          adc betalo
  1183.          sta betalo
  1184.          lda #>betaadd
  1185.          adc beta
  1186.          sta beta
  1187.          clc
  1188.          lda #<gammaadd
  1189.          adc gammalo
  1190.          sta gammalo
  1191.          lda #>gammaadd
  1192.          adc gamma
  1193.          sta gamma
  1194.          jmp mainloop
  1195.  
  1196.  
  1197.          ;perform perspective division
  1198.          ;perspektivdivision vollfuehren
  1199.  
  1200. perspect pha
  1201.          bpl nonegcrd
  1202.          pha
  1203.          tya
  1204.          clc
  1205.          eor #$ff
  1206.          adc #$01
  1207.          tay
  1208.          pla
  1209.          eor #$ff
  1210.          adc #$00
  1211. nonegcrd sta dividend+0
  1212.          sty dividend+1
  1213.          clc
  1214.          lda #$50; only positive depth
  1215.                  ;  values
  1216.                  ; nur positive tiefen-
  1217.                  ;  werte
  1218.          adc y2dcords,x
  1219.          sta divisor+0
  1220.          ldy #$00
  1221.          sty divisor+1
  1222.          iny
  1223.          sty divisor+2
  1224.          sec
  1225. divloop  ror divisor+0
  1226.          ror divisor+1
  1227.          sec
  1228.          lda dividend+1
  1229.          sbc divisor+1
  1230.          tay
  1231.          lda dividend+0
  1232.          sbc divisor+0
  1233.          bcc *+6
  1234.          sta dividend+0
  1235.          sty dividend+1
  1236.          rol divisor+2
  1237.          bcc divloop
  1238.          pla
  1239.          asl a
  1240.          lda divisor+2
  1241.          bcc *+4
  1242.          eor #$ff
  1243.          adc #$40;origin is at ($40;$40)
  1244.                  ;ursprung bei ($40;$40)
  1245.          rts
  1246.  
  1247. nmi      rti
  1248.  
  1249.  
  1250.          ; sine/cosine table
  1251.          ; sinus-/kosinustabelle
  1252.  
  1253.          *= *&$ff00+$0100
  1254. sincoslo .byte $00,$8a,$14,$9e,$28,$b1
  1255.          .byte $3a,$c2,$4a,$d1,$58,$de
  1256.          .byte $62,$e6,$69,$ea,$6b,$ea
  1257.          .byte $67,$e4,$5e,$d8,$4f,$c5
  1258.          .byte $38,$aa,$1a,$88,$f4,$5e
  1259.          .byte $c6,$2b,$8e,$ee,$4d,$a8
  1260.          .byte $01,$57,$ab,$fc,$4a,$96
  1261.          .byte $de,$24,$66,$a6,$e3,$1c
  1262.          .byte $53,$86,$b6,$e3,$0d,$33
  1263.          .byte $57,$77,$93,$ad,$c3,$d5
  1264.          .byte $e4,$f0,$f9,$fe,$ff,$fe
  1265.          .byte $f9,$f0,$e4,$d5,$c3,$ad
  1266.          .byte $93,$77,$57,$33,$0d,$e3
  1267.          .byte $b6,$86,$53,$1c,$e3,$a6
  1268.          .byte $66,$24,$de,$96,$4a,$fc
  1269.          .byte $ab,$57,$01,$a8,$4d,$ee
  1270.          .byte $8e,$2b,$c6,$5e,$f4,$88
  1271.          .byte $1a,$aa,$38,$c5,$4f,$d8
  1272.          .byte $5e,$e4,$67,$ea,$6b,$ea
  1273.          .byte $69,$e6,$62,$de,$58,$d1
  1274.          .byte $4a,$c2,$3a,$b1,$28,$9e
  1275.          .byte $14,$8a,$00,$75,$eb,$61
  1276.          .byte $d7,$4e,$c5,$3d,$b5,$2e
  1277.          .byte $a7,$21,$9d,$19,$96,$15
  1278.          .byte $94,$15,$98,$1b,$a1,$27
  1279.          .byte $b0,$3a,$c7,$55,$e5,$77
  1280.          .byte $0b,$a1,$39,$d4,$71,$11
  1281.          .byte $b2,$57,$fe,$a8,$54,$03
  1282.          .byte $b5,$69,$21,$db,$99,$59
  1283.          .byte $1c,$e3,$ac,$79,$49,$1c
  1284.          .byte $f2,$cc,$a8,$88,$6c,$52
  1285.          .byte $3c,$2a,$1b,$0f,$06,$01
  1286.          .byte $00,$01,$06,$0f,$1b,$2a
  1287.          .byte $3c,$52,$6c,$88,$a8,$cc
  1288.          .byte $f2,$1c,$49,$79,$ac,$e3
  1289.          .byte $1c,$59,$99,$db,$21,$69
  1290.          .byte $b5,$03,$54,$a8,$fe,$57
  1291.          .byte $b2,$11,$71,$d4,$39,$a1
  1292.          .byte $0b,$77,$e5,$55,$c7,$3a
  1293.          .byte $b0,$27,$a1,$1b,$98,$15
  1294.          .byte $94,$15,$96,$19,$9d,$21
  1295.          .byte $a7,$2e,$b5,$3d,$c5,$4e
  1296.          .byte $d7,$61,$eb,$75
  1297.  
  1298.          *= *+$0100
  1299. sincoshi .byte $00,$00,$01,$01,$02,$02
  1300.          .byte $03,$03,$04,$04,$05,$05
  1301.          .byte $06,$06,$07,$07,$08,$08
  1302.          .byte $09,$09,$0a,$0a,$0b,$0b
  1303.          .byte $0c,$0c,$0d,$0d,$0d,$0e
  1304.          .byte $0e,$0f,$0f,$0f,$10,$10
  1305.          .byte $11,$11,$11,$11,$12,$12
  1306.          .byte $12,$13,$13,$13,$13,$14
  1307.          .byte $14,$14,$14,$14,$15,$15
  1308.          .byte $15,$15,$15,$15,$15,$15
  1309.          .byte $15,$15,$15,$15,$15,$15
  1310.          .byte $15,$15,$15,$15,$15,$15
  1311.          .byte $15,$15,$15,$15,$15,$14
  1312.          .byte $14,$14,$14,$14,$13,$13
  1313.          .byte $13,$13,$12,$12,$12,$11
  1314.          .byte $11,$11,$11,$10,$10,$0f
  1315.          .byte $0f,$0f,$0e,$0e,$0d,$0d
  1316.          .byte $0d,$0c,$0c,$0b,$0b,$0a
  1317.          .byte $0a,$09,$09,$08,$08,$07
  1318.          .byte $07,$06,$06,$05,$05,$04
  1319.          .byte $04,$03,$03,$02,$02,$01
  1320.          .byte $01,$00,$00,$ff,$fe,$fe
  1321.          .byte $fd,$fd,$fc,$fc,$fb,$fb
  1322.          .byte $fa,$fa,$f9,$f9,$f8,$f8
  1323.          .byte $f7,$f7,$f6,$f6,$f5,$f5
  1324.          .byte $f4,$f4,$f3,$f3,$f2,$f2
  1325.          .byte $f2,$f1,$f1,$f0,$f0,$f0
  1326.          .byte $ef,$ef,$ee,$ee,$ee,$ee
  1327.          .byte $ed,$ed,$ed,$ec,$ec,$ec
  1328.          .byte $ec,$eb,$eb,$eb,$eb,$eb
  1329.          .byte $ea,$ea,$ea,$ea,$ea,$ea
  1330.          .byte $ea,$ea,$ea,$ea,$ea,$ea
  1331.          .byte $ea,$ea,$ea,$ea,$ea,$ea
  1332.          .byte $ea,$ea,$ea,$ea,$ea,$ea
  1333.          .byte $ea,$eb,$eb,$eb,$eb,$eb
  1334.          .byte $ec,$ec,$ec,$ec,$ed,$ed
  1335.          .byte $ed,$ee,$ee,$ee,$ee,$ef
  1336.          .byte $ef,$f0,$f0,$f0,$f1,$f1
  1337.          .byte $f2,$f2,$f2,$f3,$f3,$f4
  1338.          .byte $f4,$f5,$f5,$f6,$f6,$f7
  1339.          .byte $f7,$f8,$f8,$f9,$f9,$fa
  1340.          .byte $fa,$fb,$fb,$fc,$fc,$fd
  1341.          .byte $fd,$fe,$fe,$ff
  1342.  
  1343.          *= *+$0100
  1344. return   sei
  1345.          lda #$37
  1346.          sta $01
  1347.          ldx #$ff
  1348.          txs
  1349.          jsr $fda3
  1350.          lda #$00
  1351.          tay
  1352.          sta $02,y
  1353.          iny
  1354.          bne *-4
  1355.          ldx #$3c
  1356.          ldy #$03
  1357.          stx $b2
  1358.          sty $b3
  1359.          ldx #$00
  1360.          ldy #$a0
  1361.          jsr $fd8c
  1362.          jsr $fd15
  1363.          jsr $ff5b
  1364.          jsr $e3bf
  1365.          lda #$08
  1366.          sta $ba
  1367.          jmp $9000
  1368.  
  1369.